local hx__sporj = fk.CreateSkill {
  name = "hx__sporj",
  tags = { Skill.Compulsory },
}

--1
hx__sporj:addEffect(fk.EventPhaseEnd, {
  anim_type = "special",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(hx__sporj.name) then
      local x = player:getMark("@hx__sporj_phase-count")
      local y = math.max(1, player:getMark("@hx__sporj"))
      return  x >= y
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "@hx__sporj", 1)
    player.room:setPlayerMark(player, "@hx__sporj_phase-count", 0)
  end,
})

hx__sporj:addEffect(fk.EventPhaseEnd, {
  mute = true,
  priority = 2,
  can_refresh = function(self, event, target, player, data)
    if player:hasSkill(hx__sporj.name,true) then
      return true
    end
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "@hx__sporj_phase-count", 1)
  end,
})

hx__sporj:addEffect(fk.DamageInflicted, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(hx__sporj.name) and target:getMark("@hx__sporj") > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local x = target:getMark("@hx__sporj")
    local y = data.damage
    if x >= y then
      data:changeDamage(-y)
      room:removePlayerMark(target, "@hx__sporj", y)
    else
      data:changeDamage(-x)
      room:setPlayerMark(target, "@hx__sporj", 0)
    end
  end
})


return hx__sporj